<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>权限维护</title>
<link rel="stylesheet" href="${path}/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${path}/css/system.css">
<link rel="stylesheet" href="${path}/z-tree/zTreeStyle/zTreeStyle.css">
<script src="${path}/bootstrap/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="${path}/bootstrap/js/bootstrap.min.js"></script>

<script src="${path}/z-tree/jquery.ztree.all-3.5.min.js"></script>
</head>
<body>
	<div class="container-fluid" >
		<div>
			<ol class="breadcrumb">
			  <li><a href="#">当前位置:主页</a></li>
			  <li><a href="#">角色管理</a></li>
			  <li class="active">权限维护</li>
			</ol>		
			
			<div class="show_tree">
				<h4>${role.rname}的权限状态如下</h4>
				<ul id="privilegeTree" class="ztree"></ul>
				<a href="javascript:save();" class="btn btn-xs btn-info save" type="button">保存</a>
				<a href="javascript:history.back()" class="btn btn-xs btn-info back" type="button">返回</a>
				<script>
					function save(){
						//获取菜单数
						var treeObj = $.fn.zTree.getZTreeObj("privilegeTree");
						//获取选中的节点，结果为数组
						var menuArr = treeObj.getCheckedNodes(true);
						//遍历数据组,将所有选中的菜单id拼接到一个字符串中
						var mids = "";
						for(var i=0;i<menuArr.length;i++){
							var menu = menuArr[i];
							mids += menu.mid;
							mids += ",";
						}
						//发送请求保存数据
						$.post("${path}/role.do",{"method":"privilegeSave","rid":${role.rid},"mids":mids},function(data){
							if(data==1){
								alert("权限数据保存成功")
							}else{
								alert("权限数据保存失败");
							}
						});
					}
				</script>
			</div>
		</div>
	</div>
</body>
<SCRIPT type="text/javascript">
		//初始化数据
		var setting = {
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true,
					idKey: "mid",
					pIdKey: "pid",
					rootPId: 0
				},
				key:{
					name:"menuname"
				}
			}
		};
		//加载权限数据
		$(function(){
			$.post("${path}/role.do",{"method":"privilegeData","rid":${role.rid}},function(data){
				$.fn.zTree.init($("#privilegeTree"), setting, data);			},
			"json");
		});

	
</SCRIPT>
</html>